package com.zhenghaijin.commentservice.service.impl;

import com.zhenghaijin.commentservice.mapper.CommentMapper;
import com.zhenghaijin.commentservice.model.Comment;
import com.zhenghaijin.commentservice.service.CommentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Slf4j
@Service
public class CommentServiceImpl implements CommentService {
    @Autowired
    private CommentMapper commentMapper;

    @Override
    public List<Comment> getCommentsByAnimeId(Long animeId) {
        log.debug("查询动漫评论开始/Querying comments for animeId: {}", animeId);
        List<Comment> comments = commentMapper.findByAnimeId(animeId);
        log.debug("查询到{}条评论/Found {} comments for animeId: {}", comments.size(), comments.size(), animeId);
        return comments;
    }

    @Override
    public void addComment(Comment comment) {
        log.debug("添加新评论/Adding new comment - 用户ID: {}, 动漫ID: {}, 内容: {}",
                comment.getUserId(), comment.getAnimeId(), comment.getContent());
        comment.setCreatedAt(LocalDateTime.now());
        comment.setUpdatedAt(LocalDateTime.now());
        commentMapper.insert(comment);
        log.debug("评论添加成功/Comment added successfully - ID: {}", comment.getId());
    }

    @Override
    public void deleteComment(Long id) {
        log.debug("删除评论请求/Delete comment request - ID: {}", id);
        int result = commentMapper.deleteById(id);
        log.debug("删除操作结果/Delete operation result: {} (1=成功/success, 0=失败/failure)", result);
    }
}